package com.ghsc.ghxc.jsb.ui.live.fragment

import android.os.Bundle
import com.cn.appcore.base.BaseVMFragment
import com.cn.appcore.ext.loge
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.config.CustKey
import com.ghsc.ghxc.jsb.databinding.FragmentVideoListBinding
import com.ghsc.ghxc.jsb.ui.live.TabLiveVideoViewModel
import com.zj.zjsdk.ad.ZjAdError
import com.zj.zjsdk.ad.ZjContentVideo

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.live.fragment
 * 类名：VideoListFragment
 * 创建时间：2024/5/10 11:02
 * 创建人 @author： xiaolin
 * 描述 ：Todo... 光告
 */
class VideoListFragment  : BaseVMFragment<TabLiveVideoViewModel, FragmentVideoListBinding>(
    R.layout.fragment_video_list) {


    var index:Int=0
    companion object {
        fun getInstance(index:Int): VideoListFragment? {
            var fragment= VideoListFragment()
            fragment.index=index
            return fragment
        }
    }

    override fun attachVMClass(): Class<TabLiveVideoViewModel>? {
        return TabLiveVideoViewModel::class.java
    }

    override fun lazyLoad() {
        loge("lazyLoad--短视频短视频短视频短视频短视频--lazyLoad")
    }


    var contentVideo: ZjContentVideo.ContentVideoAd? = null

    override fun initView(savedInstanceState: Bundle?) {

    }


    override fun initData() {
        super.initData()
        ZjContentVideo(CustKey.zjDuanShiPing,object : ZjContentVideo.LoadListener{
            override fun onZjAdLoadSuccess(contentVideoAd: ZjContentVideo.ContentVideoAd?) {
                contentVideo = contentVideoAd
                contentVideo!!.setInteractionListener(object : ZjContentVideo.InteractionListener{
                    override fun onZjAdShowError(error: ZjAdError?) {
                        loge("短视频-onZjAdShowError ="+ error.toString())
                    }

                    override fun onPageEnter() {
                        // // 页面进入
                        loge("短视频-onZjAdShowError =")
                    }

                    override fun onPageLeave() {
                        // 页面离开
                        loge("短视频-onPageLeave =")
                    }

                    override fun onVideoStart(item: ZjContentVideo.ContentItem?) {
                        // 播放开始
                        loge("短视频-onVideoStart ="+item!!.id+item.type)
                    }

                    override fun onVideoResume(item: ZjContentVideo.ContentItem?) {
                        // 恢复播放
                        loge("短视频-onVideoResume =")
                    }

                    override fun onVideoPaused(item: ZjContentVideo.ContentItem?) {
                        // 播放暂停
                        loge("短视频-onVideoPaused =")
                    }

                    override fun onVideoCompleted(item: ZjContentVideo.ContentItem?) {
                        // 播放完成
                        loge("短视频-onVideoCompleted =")
                    }

                    override fun onVideoError(item: ZjContentVideo.ContentItem?, p1: Int, p2: Int) {
                        // 播放出错
                        loge("短视频-onVideoError ="+ p1+"=="+p2)
                    }

                })
                contentVideo!!.showAd(requireActivity(), R.id.mainFrameLayout)
            }
            override fun onZjAdLoadError(error: ZjAdError?) {
                loge("推荐视频出错==="+ error.toString())
            }

        }).loadAd()

    }

}